package cn.anecansaitin.firecrafting.client.crafting;

import cn.anecansaitin.firecrafting.ModConstant;
import cn.anecansaitin.firecrafting.api.client.crafting.IJEIRecipeRender;
import cn.anecansaitin.firecrafting.api.common.crafting.IFireRecipe;
import cn.anecansaitin.firecrafting.common.crafting.FireItemRecipe;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.world.item.ItemStack;
import oshi.util.tuples.Triplet;

import java.util.ArrayList;
import java.util.List;

public class FireItemRecipeRender implements IJEIRecipeRender {
    //这个类只需要一个就可以了，因此将构造函数设为private并提供一个静态实现。
    public static final FireItemRecipeRender INSTANCE = new FireItemRecipeRender();

    private FireItemRecipeRender() {
    }

    @Override
    public List<Triplet<ItemStack, Integer, Integer>> getResultItemSlots(IFireRecipe recipe) {
        ArrayList<Triplet<ItemStack, Integer, Integer>> list = new ArrayList<>();
        if (recipe instanceof FireItemRecipe) {
            //获取产物
            List<ItemStack> outputs = ((FireItemRecipe) recipe).getOutputs();
            //将产物按照3*3排布添加到list
            for (int i = 1; i <= 3; i++) {
                for (int j = 1; j <= 3; j++) {
                    //产物的数量不足时用空物品代替
                    if (outputs.size() >= i * j) {
                        list.add(new Triplet<>(outputs.get(i * j - 1), 106 + i * 18, -2 + j * 18));
                    } else {
                        list.add(new Triplet<>(ItemStack.EMPTY, 106 + i * 18, -2 + j * 18));
                    }
                }
            }
        }
        return list;
    }

    @Override
    public void drawBeforeFire(IFireRecipe recipe, PoseStack stack, double mouseX, double mouseY) {
        //设置贴图
        RenderSystem.setShaderTexture(0, ModConstant.JEI_GUI);
        //渲染
        GuiComponent.blit(stack, 123, 15, 179, 0, 54, 54, 256, 256);
    }
}
